package com.design.twords.config;

import android.Manifest;
import android.content.Context;
import android.content.SharedPreferences;

import com.design.twords.controller.TimeController;
import com.design.twords.utils.MyApplication;

/**
 * Create by Alen
 * Time:  13:34
 */
public class ConfigData {


    public static final String sharedName = "configData";

    // 软件所需权限列表
    public static String[] permissions = new String[]{
            Manifest.permission_group.STORAGE,
            Manifest.permission.CAMERA
    };

    //英式发音
    public static final int ENGLISH_VOICE = 1;
    //美式发音
    public static final int AMERICA_VOICE = 2;

    //顺序播放
    public static final int ORDER_PLAY = 1;
    //乱序播放
    public static final int RANDOM_PLAY = 2;

    //是否第一次打开软件
    public static boolean isFirst;
    public static String key_isFirst = "isFirst";

    //获取用户id
    public static String userId;
    public static String key_userId = "userId";
    //获取用户id
    public static String nickName;
    public static String key_nickName = "nickName";
    //获取单词播放设置
    //获取重复次数
    public static int repeatTimes;
    public static String key_repeatTimes= "repeatTimes";
    //获取间隔时间
    public static int spaceTime;
    public static String key_spaceTime= "spaceTime";
    //获取发音
    public static int song;
    public static String key_song= "song";
    //获取播放模式
    public static int playmode;
    public static String key_playmode= "playmode";
    //获取单词翻译显示
    public static boolean showTrans;
    public static String key_showTrans= "showTrans";
    //获取ocr单词id
    public static long OCRId;
    public static String key_ocrId= "ocrId";
    //获取上次ocr启动时间
    public static long lastOcrStartTime;
    public static String key_lastOcrStartTime = "lastOcrStartTime";

    public static boolean isIsFirst() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        isFirst = preferences.getBoolean(key_isFirst, true);
        return isFirst;
    }

    public static void setIsFirst(boolean isFirst) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putBoolean(key_isFirst, isFirst);
        editor.apply();
    }


    public static String getUserId() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        userId = preferences.getString(key_userId, "");
        return userId;
    }

    public static void setUserId(String userId) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putString(key_userId, userId);
        editor.apply();
    }

    public static String getNickName() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        nickName = preferences.getString(key_nickName, "");
        return nickName;
    }

    public static void setNickName(String nickName) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putString(key_nickName, nickName);
        editor.apply();
    }

    public static int getRepeatTimes() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        repeatTimes = preferences.getInt(key_repeatTimes, 3);
        return repeatTimes;
    }

    public static void setRepeatTimes(int repeatTimes) {

        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putInt(key_repeatTimes, repeatTimes);
        editor.apply();
    }

    public static int getSpaceTime() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        spaceTime = preferences.getInt(key_spaceTime, 3);
        return spaceTime;
    }

    public static void setSpaceTime(int spaceTime) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putInt(key_spaceTime, spaceTime);
        editor.apply();
    }

    public static int getSong() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        song = preferences.getInt(key_song, ENGLISH_VOICE);
        return song;
    }

    public static void setSong(int song) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putInt(key_song, song);
        editor.apply();
    }

    public static int getPlaymode() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        playmode = preferences.getInt(key_playmode, ORDER_PLAY);
        return playmode;
    }

    public static void setPlaymode(int playmode) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putInt(key_playmode, playmode);
        editor.apply();
    }

    public static boolean isShowTrans() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        showTrans = preferences.getBoolean(key_showTrans, false);
        return showTrans;
    }

    public static void setShowTrans(boolean showTrans) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putBoolean(key_showTrans, showTrans);
        editor.apply();
    }

    public static long getOCRId() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        OCRId = preferences.getLong(key_ocrId, 1);
        return OCRId;
    }

    public static void setOCRId(long OCRId) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putLong(key_ocrId, OCRId);
        editor.apply();
    }

    public static long getLastOcrStartTime() {
        SharedPreferences preferences = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        lastOcrStartTime = preferences.getLong(key_lastOcrStartTime, TimeController.getCurrentTimeStamp());
        return lastOcrStartTime;
    }

    public static void setLastOcrStartTime(long lastOcrStartTime) {
        SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences(sharedName, Context.MODE_PRIVATE).edit();
        editor.putLong(key_lastOcrStartTime, lastOcrStartTime);
        editor.apply();
    }
}
